package com.LachesismStorm.lachesism.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

/**
 * lachesism
 *
 * @Date:
 */
@Configuration
public class FileHandleConfig extends WebMvcConfigurationSupport {

    @Value("${file.image.address}")
    private String imageAddress;
    @Value("${file.log.address}")
    private String logAddress;
    @Value("${file.csv.address}")
    private String csvAddress;
    @Value("${file.doc.address}")
    private String docAddress;
    @Value("${file.icon.address}")
    private String iconAddress;
    @Value("${file.original.address}")
    private String originalIconAddress;
    @Value("${file.thumbnail.address}")
    private String thumbnailIconAddress;
    @Value("${file.equipment.address}")
    private String equipment;
    @Value("${file.character.address}")
    private String character;
    @Value("${file.ultraman.address}")
    private String ultraman;
    @Value("${file.files.address}")
    private String file;
    @Value("${file.media.address}")
    private String media;
    @Value("${file.temp.address}")
    private String temp;
    @Value("${file.base.address}")
    private String base;

    @Override
    protected void addResourceHandlers(ResourceHandlerRegistry registry) {
        //映射static路径的请求到static目录下
        // 静态资源访问路径和存放路径配置
        //registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
        // swagger访问配置
        registry.addResourceHandler("/swagger-ui/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/springfox-swagger-ui/")
                .resourceChain(false);
//      registry.addResourceHandler("doc.html").addResourceLocations("classpath:/META-INF/resources/", "classpath:/META-INF/resources/webjars/");
        //通过image访问本地的图片
        registry.addResourceHandler("/image/**").addResourceLocations("file:" + imageAddress);
        //通过nohup访问本地日志
        registry.addResourceHandler("/log/**").addResourceLocations("file:" + logAddress);
        //通过nohup访问本地CSV
        registry.addResourceHandler("/csv/**").addResourceLocations("file:" + csvAddress);
        //通过nohup访问本地doc
        registry.addResourceHandler("/doc/**").addResourceLocations("file:" + docAddress);
        //通过nohup访问原图
        registry.addResourceHandler("/icon/**").addResourceLocations("file:" + iconAddress);
        //通过nohup访问原图
        registry.addResourceHandler("/original/**").addResourceLocations("file:" + originalIconAddress);
        //通过nohup访问缩略图
        registry.addResourceHandler("/thumbnail/**").addResourceLocations("file:" + thumbnailIconAddress);
        //通过nohup访问装备图
        registry.addResourceHandler("/equipment/**").addResourceLocations("file:" + equipment);
        //通过nohup访问人物图
        registry.addResourceHandler("/character/**").addResourceLocations("file:" + character);
        //通过nohup访问奥特曼
        registry.addResourceHandler("/ultraman/**").addResourceLocations("file:" + ultraman);
        //通过nohup访问奥特曼
        registry.addResourceHandler("/files/**").addResourceLocations("file:" + file);
        registry.addResourceHandler("/media/**").addResourceLocations("file:" + media);
        registry.addResourceHandler("/base/**").addResourceLocations("file:" + base);
        registry.addResourceHandler("/temp/**").addResourceLocations("file:" + temp);

    }
}
